﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EzDesk.DesktopClient.UtilityView.ViewModel;
using EzDesk.DesktopClient.ViewContract;
using EzDesk.DesktopClient.Event;

using EzDesk.Generic;
using System.Diagnostics;

namespace EzDesk.DesktopClient.View
{
    /// <summary>
    /// Interaction logic for FeedView.xaml
    /// </summary>
    public partial class FeedView : UserControl, IFeedView
    {
        public object ViewModel
        {
            get { return this.DataContext; }
            set { this.DataContext = value; }
        }

        public CollectionViewSource updateCollectionView;
        public CollectionViewSource notificationCollectionView;


        public FeedView()
        {
            InitializeComponent();

            Keyboard.ClearFocus();

            updateCollectionView = (CollectionViewSource)(this.Resources["UpdateCollectionView"]);
            notificationCollectionView = (CollectionViewSource)(this.Resources["NotificationCollectionView"]);
        }

        public event EventHandler<GenericEventArg<string>> OnNavigate;
        public void SetFilter(Func<IFeedItemViewModel, bool> filter)
        {
            
                updateCollectionView.View.Filter = null;

            if (filter == null) return;
            else
            {

                updateCollectionView.View.Filter += (obj) =>
                        {
                            var feedItemViewModel = obj as IFeedItemViewModel;
                            if (obj == null) return false;
                            return filter(feedItemViewModel);
                        };
            }
        }

        private void listboxFeedList_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            FeedScrollViewer.ScrollToVerticalOffset(e.Delta * -1 + FeedScrollViewer.VerticalOffset);
        }

        private void updateList_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
        {
            e.Handled = true;
        }
    }
}
